<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/layui.js"></script>
    <script src="/html/js/util.js"></script>
    <link rel="stylesheet" href="/html/js/css/layui.css" media="all">
    <title>登陆页面</title>
</head>

<script>
    window.onload = function () {
        let info = getQuery("errorInfo");
        if (info == "noLand") {
            $("tips").innerHTML = "请先进行登录";
        } else if (info == "errorLevel") {
            $("tips").innerHTML = "请使用正确的权限账号进行登录";
        }

    }


    //用户登录
    async function userLogin() {
        let username = $("username").value.trim();
        let password = $("password").value.trim();
        if (username == "" || password == "") {
            alert("请不要输入无效空白的内容");
            return;
        }
        let param = {
            username: username,
            password: password
        }
        let result = await ajaxGet("/user/login", param);
        await checkUserLevel(result);
    }

    //检查账号密码并进行权限分配跳转
    async function checkUserLevel(result) {
        if (result == "顾客") {
            location.href = "/html/index.html";
        } else if (result == "管理员") {
            location.href = "/html/manager/pressOrder.html";
        } else if (result == "配送员") {
            location.href = "/html/send/sendOrder.html";
        } else if (result == "经理") {
            location.href = "/html/owner/ownerShow.html";
        } else {
            $("tips").innerHTML = "账号密码错误";
        }
    }

    //重置
    function reset() {
        $("username").value = "";
        $("password").value = "";
    }

</script>


<body style="padding-top: 50px">
<div style="padding:0 30px;display: flex;justify-content: center">
    <div>
        <label class="layui-form-label">用户名</label>
        <input type="text" name="username" id="username" required lay-verify="required" placeholder="用户名"
               autocomplete="off"
               class="layui-input" style="width: 200px">
        <br>
        <label class="layui-form-label">用户密码</label>
        <input type="text" name="password" id="password" required lay-verify="required" placeholder="用户密码"
               autocomplete="off"
               class="layui-input" style="width: 200px">
        <br>
        <div id="tips" style="color: red;margin-left: 120px"></div>
        <br>
        <button type="button" class="layui-btn" onclick="userLogin()" style="margin-left: 120px">登录</button>
        <button type="button" class="layui-btn" onclick="reset()">重置</button>
    </div>
</div>


</body>
</html>